<?php
$this->breadcrumbs=array(
	'Widgets'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'Create Widget', 'url'=>array('create')),
);

$script = "
\$('.grid-view .status-column a').live('click', function(){
    $.get(\$(this).attr('href'), function(){
        $.fn.yiiGridView.update('widget-definition-grid');
    });
    return false;
});
";
$cs = Yii::app()->clientScript;
$cs->registerScript(__CLASS__.'#ChangeStatus', $script, CClientScript::POS_READY);
$cs->registerScriptFile(Yii::app()->theme->baseUrl.'/scripts/vTip/vtip-min.js', CClientScript::POS_END);
$cs->registerCssFile(Yii::app()->theme->baseUrl.'/scripts/vTip/css/vtip.css');
?>

<h3>Manage Widgets</h2>
<style type="text/css">
.grid-view ul {padding: 0; margin: 0;}
.grid-view ul li {list-style: none;}
</style>

<?php $grid = $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'widget-definition-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
    'selectableRows'=>2,
    'selectionChanged'=>"updateSelectors",
    'afterAjaxUpdate'=>"js:function(){vtip();}",
	'columns'=>array(
        array(
            'class'=>'CCheckBoxColumn',
            'value'=>'$data->id',
            'htmlOptions'=>array('width'=>'3%'),
        ),
        array(
            'type'=>'html',
            'name'=>'name',
            'value'=>'CHtml::link($data->name, array("update", "id"=>$data->id), array("title"=>"Edit ".$data->name)).(empty($data->description) ? "" : "&nbsp;".CHtml::image(Yii::app()->theme->baseUrl."/images/log_severity2.gif", "info", array("class"=>"vtip", "title"=>nl2br($data->description), "align"=>"top")))',
        ),
        array(
            'name'=>'type',
            'value'=>'$data->typeText',
            'filter'=>$model->getTypeOptions(),
        ),
        array(
            'type'=>'html',
            'name'=>'pages',
            'value'=>'Yii::app()->controller->renderPageList($data)',
            'filter'=>false,
        ),
        array(
            'name'=>'instances',
            'type'=>'raw',
            'value'=>'CHtml::link(CHtml::image(Yii::app()->theme->baseUrl."/images/icon-widget-add.png", "Create instance"), array("updateInstance", "id"=>$data->id, "instanceId"=>0), array("title"=>"Create instance")). " " . CHtml::link(CHtml::image(Yii::app()->theme->baseUrl."/images/icon-widget-manage.png", "Manage instances"), array("admin/widgetData/admin", "WidgetData[widget_id]"=>$data->id), array("title"=>"Manage instance"))',
            'filter'=>false,
            'htmlOptions'=>array(
                'align'=>'center',
                'width'=>'60',
            ),
        ),
        array(
            'name'=>'layouts',
            'type'=>'raw',
            'value'=>'Yii::app()->controller->getLayoutList($data);',
            'filter'=>false,
            'htmlOptions'=>array(
                'class'=>'layouts-column',
            )
        ),
        array(
            'name'=>'status',
            'type'=>'raw',
            'value'=>'CHtml::link($data->statusText, array("status", "ids[]"=>$data->id, "value"=>$data->status ? 0 : 1), array("class"=>($data->status ? "active" : "")))',
            'filter'=>false,
            'sortable'=>false,
            'htmlOptions'=>array(
                'class'=>'status-column'
            )
        ),
        array(
            'name'=>'creation_datetime',
            'value'=>'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->creation_datetime))',
            'filter'=>false,
            'htmlOptions'=>array('class'=>'datetime-column'),
        ),
        array(
            'name'=>'last_update',
            'value'=>'Yii::app()->getDateFormatter()->formatDateTime(strtotime($data->last_update))',
            'filter'=>false,
            'htmlOptions'=>array('class'=>'datetime-column'),
        ),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{update} {delete}',
        ),
	),
)); 

if ($grid->dataProvider->ItemCount) {
    $this->menu[] = array('label' => 'Delete selected items', 'url'=>$this->createUrl('delete'), 'linkOptions' => array('onclick'=>'return multipleDelete("widget-definition-grid",this.href)'));
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->core->AssetUrl.'/scripts/gridview.js', CClientScript::POS_BEGIN);
?>